//
//  ViewController.m
//  Menu
//
//  Created by ZHY on 2017/7/26.
//  Copyright © 2017年 ZHY. All rights reserved.
//

#import "ViewController.h"
#import "MenuViewController.h"

@interface ViewController ()<MenuViewControllerDelegate>

@property (nonatomic,strong) UIButton *titleBtn;
@property (nonatomic,strong) MenuViewController *menu;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupUI];
}

-(void)setupUI {

    
    self.titleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.titleBtn.frame = CGRectMake(50, 100, [UIScreen mainScreen].bounds.size.width - 100, 41);
    self.titleBtn.backgroundColor = [UIColor redColor];
    [self.titleBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.view addSubview:self.titleBtn];
    [self.titleBtn addTarget:self action:@selector(titleBtnClick) forControlEvents:UIControlEventTouchUpInside];
    
    
}

-(void)titleBtnClick {

    self.menu.delegate = self;
    NSArray *titles = @[@"春藤小镇",@"万达广场",@"聚龙小镇"];
    [self.menu showMenuWithFrame:CGRectMake(self.titleBtn.frame.origin.x, CGRectGetMaxY(self.titleBtn.frame), self.titleBtn.frame.size.width, 100) titles:titles inBaseVc:self];
}

#pragma mark - MenuViewControllerDelegate
-(void)selectMenuWithIndex:(NSInteger)index title:(NSString *)title {

    [self.titleBtn setTitle:title forState:UIControlStateNormal];
}

#pragma mark - set or get

-(MenuViewController *)menu {

    if (!_menu) {
        _menu = [[MenuViewController alloc] init];
    }
    return _menu;
}

@end
